# Get names of all counts of visits
attendance_count_vars <-
	names(festival)[grepl(pattern = "n_",
												x = names(festival),
												ignore.case = F) &
										grepl(pattern = "_end",
													x = names(festival),
													ignore.case = F)]

# Get rid of rogue comment that makes this integer a character:
festival$n_men_end4[grepl(pattern = "councillor",
													x = festival$n_men_end4,
													ignore.case = TRUE)] <- NA
festival$n_men_end4 <- as.integer(as.character(festival$n_men_end4))
# Remove variables that include children and teenagers
attendance_count_vars <-
	attendance_count_vars[!grepl("children|teenager", attendance_count_vars)]

# Get total vists by men and women at all six films for every cluster
attendance <- festival[, attendance_count_vars]

# Coerce answers to integer for summation, some will be NAs
attendance <- as.data.frame(apply(attendance, 2, as.integer))

# Sum values for men and women, converting to NA when either men or women
attendance <- within(attendance, {
	n_end1 = n_men_end1 + n_women_end1
	n_end2 = n_men_end2 + n_women_end2
	n_end3 = n_men_end3 + n_women_end3
	n_end4 = n_men_end4 + n_women_end4
	n_end5 = n_men_end5 + n_women_end5
	n_end6 = n_men_end6 + n_women_end6
})

# Take mean of all festivals, ignoring ones where men or women counts
# were missing
festival$n_end_mean <- rowMeans(attendance[, c("n_end1",
																							 "n_end2",
																							 "n_end3",
																							 "n_end4",
																							 "n_end5",
																							 "n_end6")], na.rm = TRUE)


# Remove objects
rm(attendance, attendance_count_vars)


